/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package modele;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author wkhim
 */
public class DAOMySQL {

    public static Collection<Dep> getLesDeps() {
        Collection<Dep> d = new TreeSet<Dep>();
        ConnectMySQL mysqlCli = new ConnectMySQL("//localhost:3306/medecin", "root", "");
        if (mysqlCli.connect()) {
            try {
                ResultSet rs = mysqlCli.exec("select distinct departement from medecin");
                if (rs != null) {
                    while (rs.next()) {
                        d.add(new Dep(rs.getString("departement")));
                    }
                }
            } catch (SQLException ex) {
                Logger.getLogger(ConnectMySQL.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else {
            System.out.println("Mysql connection failed !!!");
        }
        mysqlCli.close();
        return d;
    }

    public static Collection<Spe> getLesSpes() {
        Collection<Spe> s = new TreeSet<Spe>();
        ConnectMySQL mysqlCli = new ConnectMySQL("//localhost:3306/medecin", "root", "");
        if (mysqlCli.connect()) {
            try {
                ResultSet rs = mysqlCli.exec("select distinct specialitecomplementaire as spe from medecin where specialitecomplementaire is not null");
                if (rs != null) {
                    while (rs.next()) {
                        s.add(new Spe(rs.getString("spe")));
                    }
                }
            } catch (SQLException ex) {
                Logger.getLogger(ConnectMySQL.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else {
            System.out.println("Mysql connection failed !!!");
        }
        mysqlCli.close();
        return s;
    }

    public static Collection<Med> getLesMeds() {
        Collection<Med> m = new TreeSet<Med>();
        ConnectMySQL mysqlCli = new ConnectMySQL("//localhost:3306/medecin", "root", "");
        if (mysqlCli.connect()) {
            try {
                ResultSet rs = mysqlCli.exec("select * from medecin");
                if (rs != null) {
                    while (rs.next()) {
                        m.add(new Med(rs.getString("nom"), rs.getString("prenom"), rs.getString("adresse"), rs.getString("tel"), rs.getString("specialitecomplementaire"), rs.getString("departement"), rs.getString("id")));
                    }
                }
            } catch (SQLException ex) {
                Logger.getLogger(ConnectMySQL.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else {
            System.out.println("Mysql connection failed !!!");
        }
        mysqlCli.close();
        return m;
    }
}
